﻿using System;
using System.Collections.Generic;

namespace Conv
{
    public class SubsamplingLayer : ITeacheble
    {
        public List<Layer> MapList { get; protected set; }
        public SubsamplingLayer(List<Layer> mapList, int resamplingRate)
        {
            MapList = new List<Layer>(mapList.Count);
            foreach (var featureMap in mapList)
            {
                //MapList.Add(new SubsamplFeatureMap(featureMap, resamplingRate,
                  //  x => (x / (resamplingRate * resamplingRate)), x => (1 / resamplingRate * resamplingRate)));//????? m.b. BUG
                //MapList.Add(new SubsamplFeatureMap(featureMap, resamplingRate,
                //   x => Math.Tanh(x), x => 1 -  Math.Tanh(x) * Math.Tanh(x)));
                // a BIG question with Subsampling layer activation function

                //Act funct from DemoMNist code
                MapList.Add(new SubsamplFeatureMap(featureMap, resamplingRate,
                   x => 1.7159 * Math.Tanh(x * 2 / 3), x => -1.44 * Math.Tanh(2 * x / 3) * Math.Tanh(2 * x / 3) + 1.44));
            }
        }

        public void Process()
        {
            foreach (var fm in MapList)
            {
                fm.Process();
            }
        }

        public void BackPropogate()
        {
            foreach (Layer FM in MapList)
            {
                FM.BackPropogate();
            }
            
        }
        public void UpdateWeight()
        {
            foreach (Layer FM in MapList)
            {
                FM.UpdateWeight();//May be here something other
            }
        }
    }
}